package bookManage;

import java.util.Scanner;

import Util.TestUtil;
import bookManage.util.BookUtil;
import bookManage.util.BorrowUtil;
import bookManage.util.CardUtil;

public class BookTest {

	static Scanner sc = new Scanner(System.in);
	
	private String admin = "admin";
	private String pass = "123";
	
	public void home() {
		while (true) {
			System.out.println("**********************");
			System.out.println("请选择：");
			System.out.println("1-用户登录");
			System.out.println("2-管理员登录");
			System.out.println("3-退出系统");
			System.out.println("**********************");

			int key = TestUtil.abnormal();
			if (key == 3)
				break;
			switch (key) {
			case 1:
				user();
				break;
			case 2:
				admin();
				break;
			default:
				break;
			}
		}
	}

	public void user() {
		CardUtil cardUtil = new CardUtil();
		while (true) {
			System.out.println("**********************");
			System.out.println("请选择：");
			System.out.println("1-登录");
			System.out.println("2-注册");
			System.out.println("3-退出");
			System.out.println("**********************");

			int key = TestUtil.abnormal();
			if (key == 3)
				break;
			switch (key) {
			case 1:
				cardUtil.login();
				break;
			case 2:
				cardUtil.add();
				break;
			default:
				break;
			}
		}
	}

	public void admin() {
		System.out.println("=========登录==========");
		System.out.print("请输入借阅卡号：");
		String cardId = sc.nextLine();
		System.out.print("请输入密码：");
		String pass = sc.nextLine();
		
		if(cardId.equals(admin) && pass.equals(this.pass)) {
			System.out.println("登录成功！");
			adminStart();
			return;
		}
		System.out.println("登录失败！");
	}

	public void userStart() {
		BookUtil bookUtil = new BookUtil();
		BorrowUtil borrowUtil = new BorrowUtil();
		while (true) {
			System.out.println("**********************");
			System.out.println("请选择：");
			System.out.println("1-查询所有图书");
			System.out.println("2-借阅图书");
			System.out.println("3-归还图书");
			System.out.println("4-查询个人借阅记录");
			System.out.println("5-退出");
			System.out.println("**********************");

			int key = TestUtil.abnormal();
			if (key == 5)
				break;
			switch (key) {
			case 1:
				bookUtil.selectAll();
				break;
			case 2:
				bookUtil.borrowBook();
				break;
			case 3:
				bookUtil.returnBook();
			case 4:
				borrowUtil.selectByUser();
				break;
			default:
				break;
			}
		}
	}
	
	public void adminStart() {
		BookUtil bookUtil = new BookUtil();
		CardUtil cardUtil = new CardUtil();
		BorrowUtil borrowUtil = new BorrowUtil();
		while (true) {
			System.out.println("**********************");
			System.out.println("请选择：");
			System.out.println("1-添加图书");
			System.out.println("2-添加借阅卡");
			System.out.println("3-查看全部图书");
			System.out.println("4-借阅卡借阅信息");
			System.out.println("5-退出");
			System.out.println("**********************");
			
			int key = TestUtil.abnormal();
			if(key==5)
				break;
			switch (key) {
			case 1:
				bookUtil.add();
				break;
			case 2:
				cardUtil.add();
				break;
			case 3:
				bookUtil.selectAll();
				break;
			case 4:
				borrowUtil.selectByCard();
				break;
			default:
				break;
			}
		}
	}

	public static void main(String[] args) {
		BookTest bookTest = new BookTest();
		bookTest.home();
	}
}
